package com.example.user_management_p1.mq;
import com.example.user_management_p1.config.CheckCodeRabbitConfig;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

import java.security.GeneralSecurityException;
import java.util.concurrent.TimeUnit;

@Component
@RabbitListener(queues = CheckCodeRabbitConfig.QUEUE_EMAIL)
public class CheckCodeReceiver {

        @Autowired
        private RedisTemplate redisTemplate;
        @Autowired
        private JavaMailSender mailSender;
        @Value("${spring.mail.from}") // 从application.yml配置文件中获取
        private String from; // 发送发邮箱地址
        @RabbitHandler
        public void process(String eamil)  {
                try {
                   SendCode.sendCheckCode(eamil,from,mailSender,redisTemplate);
                }catch (Exception e){
                        System.out.println("发送失败");
                }
        }

}
